// ==UserScript==
// @name           Conquer Club Is it my turn?
// @namespace      http://mywebsite.com/myscripts
// @description    Show me which games it is my turn for
// @include        *www.conquerclub.com/playerspace*
// ==/UserScript==
var gameListing, userName;
userNameRef = document.evaluate(
    "//a[@href='logout.php']",
    document,
    null,
    XPathResult.ANY_TYPE,
    null);
var userNameElement = userNameRef.iterateNext();
var uNameHtml = userNameElement.innerHTML;
var preName = uNameHtml.indexOf('<b>') + 3;
var postName = uNameHtml.indexOf('</b>');
var userName = uNameHtml.substring(preName, postName);

gameListing = document.evaluate(
    "//ul[@class='players']",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);

var numGames = 0;
for (var x = 0; x < gameListing.snapshotLength; x++) {
    var currentGame = gameListing.snapshotItem(x);
    if (currentGame.hasChildNodes())
    {
   	var children = currentGame.childNodes;
   	for (var i = 0; i < children.length; i++) 
   	{
   	    if (children[i].className == "status_green")
   	    {
   		if (children[i].innerHTML.indexOf(userName) >= 0)
   		{
		    numGames++;
   		    var tableRow = currentGame.parentNode.parentNode;
   		    tableRow.removeAttribute("class");
   		    tableRow.setAttribute("bgcolor", "#abc");
   		}
   	    }
    	}
    }
}
if( numGames > 0)
{
    document.title = "(" + numGames + ")" + document.title;
}

/*var currentGame = gameListing.iterateNext();
while (currentGame) { alert(currentGame.innerHTML);
if (currentGame.hasChildNodes())
 {
   var children = currentGame.childNodes;
   for (var i = 0; i < children.length; i++) 
   {
   	if (children[i].className == "status_red")
   	{
   		if (children[i].innerHTML.indexOf(userName) >= 0)
   		{
   			var tableRow = currentGame.parentNode.parentNode;
   			tableRow.removeAttribute("class");
   			tableRow.setAttribute("bgcolor", "#abc");
   		}
   	}
   }
 }
 currentGame = gameListing.iterateNext();
 alert('Bottom ' + currentGame.innerHTML);
}
*/
/*

        <ul class="players">
                <li class="status_red">
                <a class="rank0" title="New Recruit rolo's Profile" href="forum/profile.php?mode=viewprofile&amp;u=67336">rolo</a>
        (&nbsp;<a title="New Recruit rolo's Feedback" href="playerspace.php?page=reputation1&amp;username=rolo">0-0</a>&nbsp;)
                </li>

                <li class="status_green">
                <a class="rank0" title="New Recruit Hippopottoman's Profile" href="forum/profile.php?mode=viewprofile&amp;u=67337">Hippopottoman</a>
        (&nbsp;<a title="New Recruit Hippopottoman's Feedback" href="playerspace.php?page=reputation1&amp;username=Hippopottoman">0-0</a>&nbsp;)
                </li>
                <li class="status_red">
                <a class="rank2" title="Sergeant elcameron's Profile" href="forum/profile.php?mode=viewprofile&amp;u=23206">elcameron</a>
        (&nbsp;<a title="Sergeant elcameron's Feedback" href="playerspace.php?page=reputation1&amp;username=elcameron">29-1</a>&nbsp;)
                </li>

                </ul>
                
*/

